package purchase

import (
	"LogisticsPort/model"
	"LogisticsPort/sql"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

func Futures(r *gin.RouterGroup) {
	product := r.Group("/futures")
	{
		product.POST(sql.RequestAdd, futuresFeeAdd)
		product.POST(sql.RequestUpdate, futuresFeeUpdate)
		product.GET(sql.RequestList, futuresFeeList)
		product.GET(sql.RequestDelete, futuresFeeDelete)
	}
}

func futuresFeeAdd(c *gin.Context) {
	sql.HttpAdd(c, &model.FuturesFee{}, nil)
}

func futuresFeeUpdate(c *gin.Context) {
	sql.HttpUpdates(c, &model.FuturesFee{}, nil)
}

func futuresFeeDelete(c *gin.Context) {
	sql.HttpDeleteById(c, &model.FuturesFee{})
}

// FuturesFeeList /**费用（定金、尾款、税款）
func futuresFeeList(c *gin.Context) {
	sql.HttpList(c, &[]model.FuturesFee{}, func(db *gorm.DB) *gorm.DB {
		if id := c.Query("purchaseProductId"); id != "" {
			db = db.Where("purchase_product_id = ?", id)
		}
		return db
	})
}
